package com.huawei.appgallery.apkmanagement.ui;

import android.annotation.TargetApi;
import android.app.ActionBar;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.RequiresApi;
import com.huawei.appgallery.apkmanagement.impl.adapter.ApkListAdapter;
import com.huawei.appgallery.apkmanagement.impl.widget.ApkManagementFooterView;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.ui.framework.activity.BaseActivity;
import com.huawei.appgallery.foundation.ui.framework.widget.toolbar.ToolBarIcon;
import com.huawei.appgallery.packagemanager.api.bean.ManagerTask;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant.KeyAndValue;
import com.huawei.hwid.core.constants.HwAccountConstants;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import com.huawei.secure.android.common.intent.SafeIntent;
import java.io.File;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Stack;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import o.azb;
import o.bbl.d;
import o.bbl.h;
import o.bbl.j;
import o.bbn;
import o.bbo;
import o.bbq;
import o.bbs;
import o.bbw;
import o.bby;
import o.bbz;
import o.bca;
import o.bcc;
import o.bce;
import o.ccu;
import o.ccv;
import o.cdk;
import o.cdo;
import o.cdv;
import o.cdy;
import o.cdz;
import o.cfm;
import o.cfp;
import o.cgs;
import o.cgt;
import o.cgv;
import o.BaseAlertDialog;
import o.cks;
import o.ckt;
import o.cku;
import o.cny;
import o.fho;
import o.fhz;
import o.ll;

public class ApkManagementActivity extends BaseActivity implements OnClickListener, o.bbs.a, OnScrollListener {
    private ImageView ʻॱ;
    private View ʽॱ;
    private RelativeLayout ʾ;
    private TextView ʿ;
    private RelativeLayout ˈ;
    private TextView ˉ;
    private View ˊˊ;
    private ProgressBar ˊˋ;
    private ToolBarIcon ˊॱ;
    private LinearLayout ˊᐝ;
    private View ˋˊ;
    private BaseAlertDialog ˋˋ;
    private View ˋॱ;
    private List<bbq> ˋᐝ = new ArrayList();
    private View ˌ;
    private boolean ˍ = false;
    private ApkListAdapter ˎˎ = null;
    private ApkManagementFooterView ˎˏ = null;
    private Menu ˏˎ;
    private a ˏˏ = new a(this);
    private View ˏॱ;
    private boolean ˑ = true;
    private ToolBarIcon ͺ;
    private ListView ͺॱ;
    private ExecutorService ـ = Executors.newSingleThreadExecutor();
    private b ॱʼ;
    private BroadcastReceiver ॱʽ = new SafeBroadcastReceiver(this) {
        final /* synthetic */ ApkManagementActivity ˊ;

        {
            this.ˊ = r1;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            if (!this.ˊ.isFinishing()) {
                SafeIntent safeIntent = new SafeIntent(intent);
                if (ccu.ॱ.equals(safeIntent.getAction())) {
                    Object stringExtra = safeIntent.getStringExtra(ccu.ˎ);
                    if (!TextUtils.isEmpty(stringExtra)) {
                        bbs.ˎ().ˊ().remove(stringExtra);
                        bbq o_bbq = new bbq();
                        o_bbq.ॱॱ(stringExtra);
                        if (this.ˊ.ˋᐝ.remove(o_bbq)) {
                            this.ˊ.ˏˏ.removeMessages(45611321);
                            this.ˊ.ˏˏ.sendEmptyMessageDelayed(45611323, 100);
                        }
                    }
                }
            }
        }
    };
    private ToolBarIcon ॱˊ;
    private ToolBarIcon ॱˋ;
    private View ॱˎ;
    private c ॱͺ;
    private RelativeLayout ᐝॱ;

    static class a extends Handler {
        private WeakReference<o.bbs.a> ˋ;

        public a(o.bbs.a aVar) {
            this.ˋ = new WeakReference(aVar);
        }

        @TargetApi(17)
        public void handleMessage(Message message) {
            o.bbs.a aVar = (o.bbs.a) this.ˋ.get();
            if (aVar != null) {
                aVar.ॱ(message, this);
            }
        }
    }

    class b extends AsyncTask<Void, bbq, Void> {
        final /* synthetic */ ApkManagementActivity ॱ;

        private b(ApkManagementActivity apkManagementActivity) {
            this.ॱ = apkManagementActivity;
        }

        protected /* synthetic */ Object doInBackground(Object[] objArr) {
            return ॱ((Void[]) objArr);
        }

        @TargetApi(17)
        protected /* synthetic */ void onPostExecute(Object obj) {
            ˎ((Void) obj);
        }

        protected Void ॱ(Void... voidArr) {
            if (VERSION.SDK_INT < 23 || cgt.ˋ(this.ॱ) || bbw.ˏ(this.ॱ, 10002)) {
                bbn.ˎ.ˋ("ApkMActivityTag", "----->>localApk.size() : " + bbs.ˎ().ˊ().size());
                ॱ();
                this.ॱ.ˍ();
                ArrayList arrayList = new ArrayList();
                this.ॱ.ˊ((List) arrayList, bbs.ˎ().ˊ());
                int size = arrayList.size();
                for (int i = 0; i < size; i++) {
                    ॱ((String) arrayList.get(i), false, "", 0);
                }
            } else {
                bbn.ˎ.ˏ("ApkMActivityTag", "no permission");
            }
            return null;
        }

        private void ॱ() {
            fhz ˋ = fho.ˏ().ˋ("PackageManager");
            if (ˋ != null) {
                cny o_cny = (cny) ˋ.ॱ(cny.class);
                if (o_cny != null) {
                    for (ManagerTask managerTask : o_cny.ˏ(this.ॱ.getApplicationContext())) {
                        long j = 0;
                        String str = "";
                        if (managerTask.apkInfos != null) {
                            for (o.cof.a aVar : managerTask.apkInfos) {
                                if ("base".equals(aVar.ˏ) && (aVar.ॱ == 0 || aVar.ॱ == 1)) {
                                    str = aVar.ˎ;
                                }
                                j = new File(aVar.ˎ).length();
                            }
                        }
                        String str2 = str;
                        if (!TextUtils.isEmpty(str2)) {
                            ॱ(str2, true, managerTask.packageName, j);
                        }
                    }
                }
            }
        }

        private void ॱ(String str, boolean z, String str2, long j) {
            if (!TextUtils.isEmpty(str)) {
                File file = new File(str);
                Object obj = null;
                try {
                    obj = file.getCanonicalPath();
                } catch (IOException e) {
                    bbn.ˎ.ˊ("ApkMActivityTag", "can not getCanonicalPath");
                }
                if (!TextUtils.isEmpty(obj)) {
                    bbq o_bbq = new bbq();
                    o_bbq.ˏ(z);
                    o_bbq.ˏ(str2);
                    o_bbq.ॱॱ(obj);
                    if (!this.ॱ.ˋᐝ.contains(o_bbq) && file.isFile()) {
                        this.ॱ.ॱ(o_bbq, file, str, z, j);
                    }
                }
            }
        }

        @TargetApi(17)
        protected void ˎ(Void voidR) {
            super.onPostExecute(voidR);
            if (!isCancelled() && !cgt.ˋ(this.ॱ)) {
                this.ॱ.ˊˊ();
                if (this.ॱ.ˏˏ != null) {
                    this.ॱ.ˏˏ.sendEmptyMessage(45611322);
                }
            }
        }
    }

    class c extends AsyncTask<Void, String, Void> {
        final /* synthetic */ ApkManagementActivity ˊ;
        private List<String> ˋ;

        private c(ApkManagementActivity apkManagementActivity) {
            this.ˊ = apkManagementActivity;
            this.ˋ = new ArrayList();
        }

        @RequiresApi(api = 24)
        protected /* synthetic */ Object doInBackground(Object[] objArr) {
            return ˎ((Void[]) objArr);
        }

        protected /* synthetic */ void onPostExecute(Object obj) {
            ॱ((Void) obj);
        }

        protected /* synthetic */ void onProgressUpdate(Object[] objArr) {
            ˎ((String[]) objArr);
        }

        protected void onPreExecute() {
            this.ˊ.ᐝॱ();
            this.ˊ.ˑ = false;
            if (this.ˊ.getResources().getConfiguration().orientation != 1 || cdv.ˋ() >= 21) {
                this.ˊ.ˏॱ.setVisibility(8);
                this.ˊ.ˋॱ.setVisibility(8);
            } else {
                this.ˊ.ˏॱ.setVisibility(0);
                this.ˊ.ˋॱ.setVisibility(0);
            }
            if (this.ˊ.ˏˎ != null) {
                this.ˊ.ˏˎ.getItem(0).setEnabled(false);
            }
            super.onPreExecute();
        }

        @RequiresApi(api = 24)
        protected Void ˎ(Void... voidArr) {
            bbn.ˎ.ˋ("ApkMActivityTag", "RefreshLocalApksTask begin:" + System.currentTimeMillis());
            Stack stack = new Stack();
            ArrayList arrayList = new ArrayList();
            if (bbw.ˏ(this.ˊ, stack, arrayList)) {
                publishProgress(new String[0]);
                ॱ(stack, arrayList);
                List ˊ = bbs.ˎ().ˊ();
                if (!this.ˊ.ˍ || ˊ.size() < this.ˋ.size()) {
                    bbs.ˎ().ˊ().clear();
                    this.ˊ.ˊ(bbs.ˎ().ˊ(), this.ˋ);
                    this.ˊ.ˋᐝ();
                }
                bbn.ˎ.ˋ("ApkMActivityTag", "RefreshLocalApksTask end:" + System.currentTimeMillis());
            } else {
                bbn.ˎ.ˋ("ApkMActivityTag", "RefreshLocalApksTask end without storage permission:" + System.currentTimeMillis());
            }
            return null;
        }

        private void ॱ(Stack<String> stack, ArrayList<String> arrayList) {
            this.ˊ.ˋᐝ.clear();
            this.ˋ.clear();
            ˊ();
            while (stack.size() > 0 && !this.ˊ.ˍ) {
                bca.ˏ(stack, arrayList, new bce(this) {
                    final /* synthetic */ c ˎ;

                    {
                        this.ˎ = r1;
                    }

                    public void ˊ(File file, String str) {
                        if (this.ˎ.ˋ(file, str, false, "", 0)) {
                            this.ˎ.publishProgress(new String[0]);
                        }
                    }

                    public void ˋ(String str) {
                        this.ˎ.publishProgress(new String[]{str});
                    }
                });
            }
        }

        private void ˊ() {
            fhz ˋ = fho.ˏ().ˋ("PackageManager");
            if (ˋ != null) {
                cny o_cny = (cny) ˋ.ॱ(cny.class);
                if (o_cny != null) {
                    int i = 0;
                    for (ManagerTask managerTask : o_cny.ˏ(this.ˊ.getApplicationContext())) {
                        int i2;
                        long j = 0;
                        String str = "";
                        if (managerTask.apkInfos != null) {
                            for (o.cof.a aVar : managerTask.apkInfos) {
                                if ("base".equals(aVar.ˏ) && (aVar.ॱ == 0 || aVar.ॱ == 1)) {
                                    str = aVar.ˎ;
                                }
                                j = new File(aVar.ˎ).length();
                            }
                        }
                        String str2 = str;
                        if (TextUtils.isEmpty(str2)) {
                            i2 = i;
                        } else {
                            i2 = ˋ(new File(str2), str2, true, managerTask.packageName, j) | i;
                        }
                        i = i2;
                    }
                    if (i != 0) {
                        bbn.ˎ.ˋ("ApkMActivityTag", "find self apks:" + this.ˊ.ˋᐝ.size());
                        publishProgress(new String[0]);
                    }
                }
            }
        }

        private boolean ˋ(File file, String str, boolean z, String str2, long j) {
            try {
                String canonicalPath = file.getCanonicalPath();
                bbq o_bbq = new bbq();
                o_bbq.ॱॱ(canonicalPath);
                o_bbq.ˏ(str2);
                o_bbq.ˏ(z);
                if (this.ˊ.ˋᐝ.contains(o_bbq) || this.ˋ.contains(str)) {
                    return false;
                }
                this.ˋ.add(str);
                this.ˊ.ॱ(o_bbq, file, str, z, j);
                return true;
            } catch (IOException e) {
                return false;
            }
        }

        protected void ˎ(String... strArr) {
            super.onProgressUpdate(strArr);
            if (this.ˊ.ˏˏ == null) {
                return;
            }
            if (strArr.length == 1) {
                Message obtainMessage = this.ˊ.ˏˏ.obtainMessage();
                obtainMessage.what = 45611325;
                obtainMessage.obj = strArr[0];
                this.ˊ.ˏˏ.sendMessage(obtainMessage);
                return;
            }
            this.ˊ.ˏˏ.sendEmptyMessage(45611321);
        }

        protected void ॱ(Void voidR) {
            if (this.ˊ.ˏˎ != null) {
                this.ˊ.ˏˎ.getItem(0).setEnabled(true);
            }
            super.onPostExecute(voidR);
            this.ˊ.ͺ();
            if (this.ˊ.ˏˏ != null) {
                bbn.ˎ.ˋ("ApkMActivityTag", "get local apk end!" + this.ˋ.size());
                this.ˊ.ˏˏ.sendEmptyMessage(45611322);
            }
        }
    }

    class e extends AsyncTask<bbq, Void, Void> {
        final /* synthetic */ ApkManagementActivity ˎ;

        private e(ApkManagementActivity apkManagementActivity) {
            this.ˎ = apkManagementActivity;
        }

        protected /* synthetic */ Object doInBackground(Object[] objArr) {
            return ˏ((bbq[]) objArr);
        }

        @TargetApi(17)
        protected /* synthetic */ void onPostExecute(Object obj) {
            ˊ((Void) obj);
        }

        protected /* synthetic */ void onProgressUpdate(Object[] objArr) {
            ˊ((Void[]) objArr);
        }

        protected void onPreExecute() {
            this.ˎ.ᐝॱ();
            super.onPreExecute();
        }

        protected Void ˏ(bbq... o_bbqArr) {
            bbq o_bbq;
            if (o_bbqArr == null || o_bbqArr.length <= 0) {
                o_bbq = null;
            } else {
                o_bbq = o_bbqArr[0];
            }
            if (o_bbq == null) {
                ArrayList arrayList = new ArrayList();
                this.ˎ.ˊ((List) arrayList, this.ˎ.ˋᐝ);
                for (int i = 0; i < arrayList.size(); i++) {
                    o_bbq = (bbq) arrayList.get(i);
                    if (this.ˎ.ˎ(o_bbq)) {
                        this.ˎ.ˋᐝ.remove(o_bbq);
                        publishProgress(new Void[0]);
                    } else {
                        bbn.ˎ.ˏ("ApkMActivityTag", "delete apk failed!!!" + o_bbq.ˎ());
                    }
                }
            } else if (this.ˎ.ˎ(o_bbq)) {
                this.ˎ.ˋᐝ.remove(o_bbq);
                publishProgress(new Void[0]);
            } else {
                bbn.ˎ.ˊ("ApkMActivityTag", "delete apk failed!!!" + o_bbq.ˎ());
            }
            Intent intent = new Intent();
            intent.setAction(ccv.ˋ());
            intent.setPackage(bbo.ˎ().getPackageName());
            bbo.ˎ().sendBroadcast(intent);
            return null;
        }

        protected void ˊ(Void... voidArr) {
            if (this.ˎ.ˏˏ != null) {
                this.ˎ.ˏˏ.sendEmptyMessage(45611321);
            }
            super.onProgressUpdate(voidArr);
        }

        @TargetApi(17)
        protected void ˊ(Void voidR) {
            super.onPostExecute(voidR);
            if (!isCancelled() && !this.ˎ.isFinishing()) {
                if (this.ˎ.ॱͺ == null || this.ˎ.ॱͺ.getStatus() != Status.RUNNING) {
                    this.ˎ.ͺ();
                    this.ˎ.ˊˊ();
                    if (this.ˎ.ˏˏ != null) {
                        this.ˎ.ˏˏ.sendEmptyMessage(45611322);
                        return;
                    }
                    return;
                }
                bbn.ˎ.ˎ("ApkMActivityTag", "refreshLocalApksTask is running!!");
            }
        }
    }

    public void ॱ(Message message, Handler handler) {
        if (!cgt.ˋ(this)) {
            switch (message.what) {
                case 45611321:
                    handler.removeMessages(45611321);
                    handler.sendEmptyMessageDelayed(45611323, 100);
                    return;
                case 45611322:
                    this.ˑ = true;
                    ˎ(1);
                    handler.removeMessages(45611323);
                    handler.removeMessages(45611321);
                    if (getResources().getConfiguration().orientation == 1 && cdv.ˋ() < 21) {
                        this.ˏॱ.setVisibility(0);
                        this.ˋॱ.setVisibility(0);
                    }
                    ॱˊ();
                    return;
                case 45611323:
                    ॱˊ();
                    return;
                case 45611324:
                    ˋˋ();
                    return;
                case 45611325:
                    String str = (String) message.obj;
                    if (!this.ˑ && !TextUtils.isEmpty(str)) {
                        this.ˎˏ.setmSubPrompt(str);
                        this.ˉ.setText(str);
                        this.ʿ.setText(str);
                        return;
                    }
                    return;
                default:
                    return;
            }
        }
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        if (bbo.ˎ() == null) {
            bbo.ˊ(getApplicationContext());
        }
        setContentView(o.bbl.e.ˊ);
        cgv.ˋ(this, d.ˊ, d.ˋ);
        getWindow().getDecorView().setBackgroundColor(getResources().getColor(d.ˏ));
        ˋˊ();
        String format = new SimpleDateFormat("yyyyMMdd", Locale.US).format(new Date());
        if (bbz.ˋ().equals(format)) {
            ʼॱ();
            ᐝ();
        } else {
            ˏ(format);
        }
        SafeIntent safeIntent = new SafeIntent(getIntent());
        Object obj = "";
        format = "";
        if (safeIntent.hasExtra("eventkey") && safeIntent.hasExtra("eventvalue")) {
            obj = safeIntent.getStringExtra("eventkey");
            format = safeIntent.getStringExtra("eventvalue");
        }
        if (!TextUtils.isEmpty(obj)) {
            cdk.ॱ(bbo.ˎ(), obj, format);
        }
        ll.ˏ(getApplicationContext()).ˏ(this.ॱʽ, new IntentFilter(ccu.ॱ));
    }

    private void ᐝ() {
        if (this.ॱʼ != null) {
            this.ॱʼ.cancel(true);
        }
        this.ॱʼ = new b();
        this.ॱʼ.executeOnExecutor(this.ـ, new Void[0]);
    }

    private void ˏ(String str) {
        bbz.ˎ(str);
        this.ॱͺ = new c();
        this.ॱͺ.executeOnExecutor(this.ـ, new Void[0]);
    }

    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        if (configuration != null && cdv.ˋ() < 21) {
            ˊᐝ();
        }
    }

    private void ॱˊ() {
        if (cgs.ˋ(this.ˋᐝ)) {
            this.ˈ.setVisibility(8);
            this.ᐝॱ.setVisibility(0);
            this.ʿ.setVisibility(0);
            this.ˊॱ.invalidate();
            if (cdv.ˋ() < 21) {
                this.ॱˋ.setDisable(getResources().getDrawable(o.bbl.a.ˋ));
                this.ʻॱ.setImageResource(o.bbl.a.ˋ);
                this.ॱˎ.setClickable(false);
                return;
            } else if (this.ˏˎ != null) {
                ˋ(this.ˏˎ);
                return;
            } else {
                return;
            }
        }
        this.ˈ.setVisibility(0);
        this.ᐝॱ.setVisibility(8);
        this.ʿ.setVisibility(8);
        List arrayList = new ArrayList();
        ˊ(arrayList, this.ˋᐝ);
        if (this.ˎˎ == null) {
            this.ˎˎ = new ApkListAdapter(arrayList, this, this);
            this.ͺॱ.setAdapter(this.ˎˎ);
        } else {
            this.ˎˎ.setData(arrayList);
        }
        if (cdv.ˋ() < 21) {
            this.ʻॱ.setImageResource(o.bbl.a.ˎ);
            this.ॱˎ.setClickable(true);
        } else if (this.ˏˎ != null) {
            this.ˏˎ.clear();
            getMenuInflater().inflate(h.ॱ, this.ˏˎ);
            this.ˏˎ.findItem(o.bbl.b.ˏ).setEnabled(true);
        }
    }

    private void ˋ(Menu menu) {
        MenuItem findItem = menu.findItem(o.bbl.b.ˏ);
        findItem.setEnabled(false);
        CharSequence spannableString = new SpannableString(findItem.getTitle());
        spannableString.setSpan(new ForegroundColorSpan(getResources().getColor(d.ॱ)), 0, spannableString.length(), 0);
        findItem.setTitle(spannableString);
    }

    private void ͺ() {
        this.ʾ.setVisibility(0);
        this.ʽॱ.setVisibility(8);
    }

    private void ᐝॱ() {
        this.ʾ.setVisibility(8);
        this.ʽॱ.setVisibility(0);
    }

    private void ʼॱ() {
        if (this.ˊˊ != null) {
            this.ˊˊ.setVisibility(0);
            this.ˊˋ.setVisibility(0);
        }
    }

    private void ˊˊ() {
        if (this.ˊˊ != null) {
            this.ˊˊ.setVisibility(8);
            this.ˊˋ.setVisibility(8);
        }
    }

    private void ˋˊ() {
        this.ˏॱ = findViewById(o.bbl.b.ʿ);
        azb.ˏ(this.ˏॱ);
        this.ˋॱ = findViewById(o.bbl.b.ʼॱ);
        int ˏ = cdo.ˏ(this);
        ˊˋ();
        this.ᐝॱ = (RelativeLayout) findViewById(o.bbl.b.ʽॱ);
        azb.ˏ(this.ᐝॱ);
        this.ʾ = (RelativeLayout) findViewById(o.bbl.b.ˈ);
        this.ʽॱ = findViewById(o.bbl.b.ʾ);
        this.ʿ = (TextView) this.ʽॱ.findViewById(o.bbl.b.ॱˊ);
        this.ˈ = (RelativeLayout) findViewById(o.bbl.b.ˉ);
        this.ͺ = (ToolBarIcon) findViewById(o.bbl.b.ʻॱ);
        this.ͺ.setOnClickListener(this);
        ˊ(this.ͺ, ˏ);
        this.ˊॱ = (ToolBarIcon) findViewById(o.bbl.b.ॱ);
        this.ˊॱ.setOnClickListener(this);
        ˊ(this.ˊॱ, ˏ);
        this.ॱˊ = (ToolBarIcon) findViewById(o.bbl.b.ʼ);
        this.ॱˊ.setOnClickListener(this);
        ˊ(this.ॱˊ, ˏ);
        this.ॱˋ = (ToolBarIcon) findViewById(o.bbl.b.ˏ);
        this.ॱˋ.setEnabled(false);
        ˊ(this.ॱˋ, ˏ);
        this.ˊᐝ = (LinearLayout) findViewById(o.bbl.b.ˊॱ);
        azb.ˏ(this.ˊᐝ);
        this.ˉ = (TextView) this.ˊᐝ.findViewById(o.bbl.b.ˊˊ);
        this.ͺॱ = (ListView) findViewById(o.bbl.b.ˊ);
        this.ͺॱ.setOnScrollListener(this);
        this.ˎˏ = new ApkManagementFooterView(this);
        this.ˎˏ.setShowFootView(false);
        this.ͺॱ.addFooterView(this.ˎˏ);
        this.ˊˊ = findViewById(o.bbl.b.ˎ);
        azb.ˏ(this.ˊˊ);
        this.ˊˋ = (ProgressBar) this.ˊˊ.findViewById(o.bbl.b.ͺ);
    }

    private void ˊ(ToolBarIcon toolBarIcon, int i) {
        LayoutParams layoutParams = (LayoutParams) toolBarIcon.getLayoutParams();
        layoutParams.gravity = 17;
        layoutParams.width = i;
        toolBarIcon.setLayoutParams(layoutParams);
    }

    private void ˊˋ() {
        this.ˋˊ = findViewById(o.bbl.b.ˊᐝ);
        azb.ˏ(this.ˋˊ);
        this.ˌ = findViewById(o.bbl.b.ˊˋ);
        azb.ˏ(this.ˌ);
        View findViewById = findViewById(o.bbl.b.ˋˊ);
        this.ॱˎ = findViewById(o.bbl.b.ʽ);
        this.ʻॱ = (ImageView) findViewById(o.bbl.b.ᐝ);
        findViewById.setOnClickListener(this);
        this.ॱˎ.setOnClickListener(this);
        ActionBar actionBar;
        if (cdv.ˋ() >= 21) {
            actionBar = getActionBar();
            if (actionBar != null) {
                actionBar.setDisplayHomeAsUpEnabled(true);
                actionBar.setTitle(getString(j.ᐝ));
                actionBar.show();
                ˏ(this.ˏˎ);
                return;
            }
            ˊᐝ();
            return;
        }
        ˊᐝ();
        actionBar = getActionBar();
        if (actionBar != null) {
            actionBar.hide();
        }
    }

    private void ˊᐝ() {
        if (getApplicationContext().getResources().getConfiguration().orientation == 2) {
            this.ˏॱ.setVisibility(8);
            this.ˋॱ.setVisibility(8);
            this.ˋˊ.setVisibility(8);
            this.ˌ.setVisibility(0);
            ((LinearLayout) this.ˌ.findViewById(o.bbl.b.ॱॱ)).setOnClickListener(new ckt(new OnClickListener(this) {
                final /* synthetic */ ApkManagementActivity ˏ;

                {
                    this.ˏ = r1;
                }

                public void onClick(View view) {
                    this.ˏ.onBackPressed();
                }
            }));
            return;
        }
        this.ˋˊ.setVisibility(0);
        this.ˌ.setVisibility(8);
        ((LinearLayout) this.ˋˊ.findViewById(o.bbl.b.ॱॱ)).setOnClickListener(new ckt(new OnClickListener(this) {
            final /* synthetic */ ApkManagementActivity ˎ;

            {
                this.ˎ = r1;
            }

            public void onClick(View view) {
                this.ˎ.onBackPressed();
            }
        }));
        this.ˏॱ.setVisibility(0);
        this.ˋॱ.setVisibility(0);
    }

    private void ˏ(Menu menu) {
        this.ˏॱ.setVisibility(8);
        this.ˋॱ.setVisibility(8);
        if (menu != null) {
            menu.clear();
            getMenuInflater().inflate(h.ॱ, menu);
            if (cgs.ˋ(this.ˋᐝ)) {
                ˋ(menu);
            }
            this.ˏˎ = menu;
        }
    }

    public void onDestroy() {
        this.ˍ = true;
        super.onDestroy();
        if (this.ˋˋ != null) {
            this.ˋˋ.ˏ();
            this.ˋˋ = null;
        }
        if (this.ॱʽ != null) {
            ll.ˏ(getApplicationContext()).ˋ(this.ॱʽ);
        }
        this.ـ.shutdownNow();
        if (this.ॱʼ != null && !this.ॱʼ.isCancelled()) {
            this.ॱʼ.cancel(true);
        }
    }

    public void onPause() {
        super.onPause();
    }

    public void onResume() {
        super.onResume();
        cdk.ॱ(this, cdk.ˏ((Context) this, j.ʻ), KeyAndValue.NUMBER_01);
    }

    public void onClick(View view) {
        if (view != null) {
            int id = view.getId();
            if (o.bbl.b.ʻॱ == id || o.bbl.b.ˋˊ == id || o.bbl.b.ॱ == id) {
                ˌ();
            } else if (o.bbl.b.ʼ == id || o.bbl.b.ʽ == id) {
                ˎˎ();
            } else if (o.bbl.b.ˏॱ == id) {
                Object tag = view.getTag();
                if (tag != null && (tag instanceof bbq)) {
                    ˏ((bbq) tag);
                }
            }
        }
    }

    private void ˏ(final bbq o_bbq) {
        if (!cgt.ˋ(this)) {
            if (this.ˋˋ == null || !this.ˋˋ.ˎ()) {
                this.ˋˋ = BaseAlertDialog.ˋ(this, null, String.format(Locale.ENGLISH, getResources().getString(j.ॱ), new Object[]{o_bbq.ˏ()}));
                this.ˋˋ.ॱ();
                this.ˋˋ.ॱ(BaseAlertDialog.a.CONFIRM, getResources().getString(j.ˎ));
                this.ˋˋ.ˎ(new cks(this) {
                    final /* synthetic */ ApkManagementActivity ˏ;

                    public void enableNetworking() {
                        if (o_bbq != null) {
                            new e().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new bbq[]{o_bbq});
                        }
                    }

                    public void upgrade() {
                    }

                    public void ˋ() {
                    }
                });
            }
        }
    }

    private void ˉ() {
        if (!cgt.ˋ(this)) {
            this.ˋˋ = BaseAlertDialog.ˋ(this, null, getString(j.ˊ));
            this.ˋˋ.ॱ();
            this.ˋˋ.ॱ(BaseAlertDialog.a.CONFIRM, getResources().getString(j.ˎ));
            this.ˋˋ.ˎ(new cks(this) {
                final /* synthetic */ ApkManagementActivity ॱ;

                {
                    this.ॱ = r1;
                }

                public void enableNetworking() {
                    new e().execute(new bbq[0]);
                }

                public void upgrade() {
                }

                public void ˋ() {
                }
            });
        }
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        ˊ(menu);
        return true;
    }

    private void ˊ(Menu menu) {
        if (cdv.ˋ() >= 21 && menu != null) {
            menu.clear();
            getMenuInflater().inflate(h.ॱ, menu);
            if (cgs.ˋ(this.ˋᐝ)) {
                ˋ(menu);
            }
            this.ˏˎ = menu;
        }
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() == 16908332) {
            finish();
            return true;
        } else if (menuItem.getItemId() == o.bbl.b.ॱ) {
            ˌ();
            return true;
        } else if (menuItem.getItemId() != o.bbl.b.ˏ) {
            return super.onOptionsItemSelected(menuItem);
        } else {
            ˎˎ();
            return true;
        }
    }

    private void ˎˎ() {
        String userId = UserSession.getInstance().getUserId();
        cdk.ॱ(this, getString(j.ʽ), "03|" + userId + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + cdz.ˎ());
        if (!this.ˋᐝ.isEmpty()) {
            ˉ();
        }
    }

    private void ˌ() {
        String userId = UserSession.getInstance().getUserId();
        cdk.ॱ(this, getString(j.ʽ), "02|" + userId + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + cdz.ˎ());
        if (this.ॱͺ != null) {
            this.ॱͺ.cancel(true);
        }
        this.ॱͺ = new c();
        this.ॱͺ.executeOnExecutor(this.ـ, new Void[0]);
    }

    private boolean ˎ(bbq o_bbq) {
        Exception e;
        boolean z = false;
        if (o_bbq == null || TextUtils.isEmpty(o_bbq.ˎ())) {
            return false;
        }
        bbn.ˎ.ˎ("ApkMActivityTag", "begin to delete Apk:" + o_bbq.ˎ());
        File file = new File(o_bbq.ˎ());
        if (file.exists() && file.isFile()) {
            for (int i = 0; i < 3; i++) {
                z = file.delete();
                if (z) {
                    bbn.ˎ.ˎ("ApkMActivityTag", "DELETE APK SUCCESSFUL,PATH:" + o_bbq);
                    ˊ(o_bbq);
                    return true;
                }
            }
            boolean ˏ;
            try {
                ˏ = bcc.ˏ(bbo.ˎ().getContentResolver(), file);
                if (!ˏ) {
                    return ˏ;
                }
                try {
                    bbn.ˎ.ˎ("ApkMActivityTag", "DELETE APK SUCCESSFUL :MediaFile,PATH:" + o_bbq);
                    return ˏ;
                } catch (Exception e2) {
                    e = e2;
                    bbn.ˎ.ˏ("ApkMActivityTag", "DELETE APK :MediaFile,IOException, " + e.toString());
                    return ˏ;
                }
            } catch (Exception e3) {
                Exception exception = e3;
                ˏ = z;
                e = exception;
                bbn.ˎ.ˏ("ApkMActivityTag", "DELETE APK :MediaFile,IOException, " + e.toString());
                return ˏ;
            }
        }
        bbn.ˎ.ˎ("ApkMActivityTag", "DELETE APK SUCCESSFUL,file not exist!!!PATH:" + o_bbq);
        ˊ(o_bbq);
        return true;
    }

    private void ˊ(bbq o_bbq) {
        if (o_bbq.ʼ()) {
            fhz ˋ = fho.ˏ().ˋ("PackageManager");
            if (ˋ != null) {
                cny o_cny = (cny) ˋ.ॱ(cny.class);
                if (o_cny != null) {
                    o_cny.ˊ(getApplicationContext(), o_bbq.ˋ());
                }
            }
        }
    }

    private void ˋᐝ() {
        new cfp(cfm.ˊ(".ApkManagementInfo")).ˎ((ArrayList) bbs.ˎ().ˊ());
    }

    private void ˍ() {
        List list = (ArrayList) new cfp(cfm.ˊ(".ApkManagementInfo")).ˎ();
        if (list != null && !list.isEmpty()) {
            ˊ(bbs.ˎ().ˊ(), list);
        }
    }

    private void ˋˋ() {
        cku ˏ = cku.ˏ(this, cku.class, getString(j.ॱॱ), getString(j.ˋ));
        ˏ.ॱ(-1, getString(j.ˋॱ));
        ˏ.ॱ(new cks(this) {
            final /* synthetic */ ApkManagementActivity ˎ;

            {
                this.ˎ = r1;
            }

            public void enableNetworking() {
                try {
                    Intent intent = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS");
                    intent.setData(Uri.fromParts(HiAnalyticsConstant.BI_KEY_PACKAGE, this.ˎ.getPackageName(), null));
                    this.ˎ.startActivity(intent);
                } catch (ActivityNotFoundException e) {
                    bbn.ˎ.ˋ("ApkMActivityTag", "startActivity MANAGE_APP_PERMISSIONS failed! e = " + e.getMessage());
                }
            }

            public void upgrade() {
            }

            public void ˋ() {
            }
        });
        ˏ.ˋ((Context) this, "ApkMActivityTag");
    }

    @TargetApi(23)
    public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
        super.onRequestPermissionsResult(i, strArr, iArr);
        if (!(strArr == null || iArr == null || iArr.length <= 0)) {
            int i2 = 0;
            while (i2 < strArr.length) {
                if (strArr.length > i2 && strArr[i2].equals("android.permission.WRITE_EXTERNAL_STORAGE") && iArr[i2] == 0) {
                    ˏ(i);
                    return;
                }
                i2++;
            }
        }
        if (!isFinishing() && !shouldShowRequestPermissionRationale("android.permission.WRITE_EXTERNAL_STORAGE") && this.ˏˏ != null) {
            this.ˏˏ.sendEmptyMessage(45611324);
        }
    }

    private void ˏ(int i) {
        if (10002 == i) {
            ᐝ();
        } else if (10001 == i) {
            if (this.ॱͺ != null) {
                this.ॱͺ.cancel(true);
            }
            this.ॱͺ = new c();
            this.ॱͺ.executeOnExecutor(this.ـ, new Void[0]);
        }
    }

    private void ॱ(bbq o_bbq) {
        String[] split = o_bbq.ˎ().split("/");
        if (split.length > 1) {
            o_bbq.ˊ(split[split.length - 1]);
            o_bbq.ˎ(bbo.ˎ().getString(j.ˏ));
            o_bbq.ॱ(false);
            this.ˋᐝ.add(o_bbq);
        }
    }

    private void ॱ(bbq o_bbq, File file, String str, boolean z, long j) {
        PackageInfo packageArchiveInfo = bbo.ˎ().getPackageManager().getPackageArchiveInfo(str, 0);
        if (packageArchiveInfo != null) {
            ApplicationInfo applicationInfo = packageArchiveInfo.applicationInfo;
            if (applicationInfo != null) {
                o_bbq.ˎ(new SimpleDateFormat("yyyy-MM-dd", Locale.US).format(new Date(file.lastModified())));
                o_bbq.ˏ(applicationInfo.packageName);
                if (z) {
                    o_bbq.ॱ(cfm.ˎ(j));
                } else {
                    o_bbq.ॱ(cfm.ˎ(file.length()));
                }
                o_bbq.ˋ(String.valueOf(packageArchiveInfo.versionCode));
                o_bbq.ˎ(bby.ˊ(getApplicationContext(), packageArchiveInfo.versionName == null ? HwAccountConstants.NULL : packageArchiveInfo.versionName));
                o_bbq.ˊ(bby.ˋ(getApplicationContext(), applicationInfo, str));
                this.ˋᐝ.add(o_bbq);
                return;
            }
            return;
        }
        ॱ(o_bbq);
    }

    private void ˊ(List list, List list2) {
        if (list != null && list2 != null) {
            try {
                list.addAll(list2);
            } catch (NullPointerException e) {
                bbn.ˎ.ˏ("ApkMActivityTag", e.toString() + " accoued , copyArray " + list + " to " + list2);
            }
        }
    }

    public void onScrollStateChanged(AbsListView absListView, int i) {
        if (i == 2) {
            cdy.ˊ(true);
        } else {
            cdy.ˊ(false);
        }
    }

    public void onScroll(AbsListView absListView, int i, int i2, int i3) {
        if (!this.ˑ) {
            if (i + i2 < i3 || absListView == null || absListView.getChildAt((i + i2) - 1) == null || absListView.getBottom() < absListView.getChildAt((i + i2) - 1).getBottom()) {
                ˎ(3);
            } else {
                ˎ(2);
            }
        }
    }

    private void ˎ(int i) {
        switch (i) {
            case 1:
                this.ˎˏ.setShowFootView(false);
                this.ˊᐝ.setVisibility(8);
                return;
            case 2:
                this.ˎˏ.setShowFootView(true);
                this.ˊᐝ.setVisibility(8);
                return;
            case 3:
                this.ˎˏ.setShowFootView(false);
                this.ˊᐝ.setVisibility(0);
                return;
            default:
                return;
        }
    }
}
